package com.zcp.todayheadline;

import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_set)
public class SetActivity extends AppCompatActivity implements View.OnClickListener {

    @ViewInject(R.id.image_set_arrow)
    ImageView image_set_arrow;

    @ViewInject(R.id.re_set_clear)
    RelativeLayout re_set_clear;

    @ViewInject(R.id.re_set_textsize)
    RelativeLayout re_set_textsize;

    @ViewInject(R.id.re_set_liebiao)
    RelativeLayout re_set_liebiao;

    @ViewInject(R.id.re_set_wifi)
    RelativeLayout re_set_wifi;

    @ViewInject(R.id.re_set_tuisong)
    RelativeLayout re_set_tuisong;

    @ViewInject(R.id.re_set_lixian)
    RelativeLayout re_set_lixian;

    @ViewInject(R.id.re_set_check)
    RelativeLayout re_set_check;

    @ViewInject(R.id.re_clear_finish)
    RelativeLayout re_clear_finish;

    AlertDialog.Builder builder1;
    AlertDialog create;

    @ViewInject(R.id.tv_clear)
    TextView tv_clear;

    @ViewInject(R.id.tv_show_wifi)
    TextView tv_show_wifi;

    @ViewInject(R.id.tv_small)
    TextView tv_small;

    @ViewInject(R.id.tv_mid)
    TextView tv_mid;

    @ViewInject(R.id.tv_big)
    TextView tv_big;

    @ViewInject(R.id.tv_teda)
    TextView tv_teda;

    @ViewInject(R.id.rb_small)
    RadioButton rb_small;

    @ViewInject(R.id.rb_mid)
    RadioButton rb_mid;

    @ViewInject(R.id.rb_big)
    RadioButton rb_big;

    @ViewInject(R.id.rb_teda)
    RadioButton rb_teda;

    View view;

    //handler发送消息
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int x = msg.what;
            create.dismiss();
            //显示
            re_clear_finish.setVisibility(View.VISIBLE);
            //重新赋值
            tv_clear.setText(0 + "B");

            //发送延迟消息
            handler.sendEmptyMessageDelayed(2, 1000);

            //判断
            if (x == 2) {
                //隐藏
                re_clear_finish.setVisibility(View.GONE);
            }

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);

        //找控件
        initView();
    }

    //找控件
    public void initView() {
        //返回按钮
        image_set_arrow = (ImageView) findViewById(R.id.image_set_arrow);

        //清除缓存
        tv_clear = (TextView) findViewById(R.id.tv_clear);

        //找对话框布局
        view = View.inflate(SetActivity.this, R.layout.dialog_set, null);

        //按钮监听
        image_set_arrow.setOnClickListener(this);
        re_set_clear.setOnClickListener(this);
        re_set_textsize.setOnClickListener(this);
        re_set_liebiao.setOnClickListener(this);
        re_set_wifi.setOnClickListener(this);
        re_set_tuisong.setOnClickListener(this);
        re_set_lixian.setOnClickListener(this);
        re_set_check.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_set_arrow:
                onBackPressed();
                break;
            case R.id.re_set_clear:
                final AlertDialog.Builder builder = new AlertDialog.Builder(SetActivity.this);

                //标题
                builder.setTitle("提示");

                //信息
                builder.setMessage("确定要删除所有缓存吗?问答革稿,离线内容及图片均会被清除.");

                //取消按钮
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        //取消对话框
                        dialog.cancel();
                    }
                });

                //确定按钮
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        //取消对话框
                        dialog.dismiss();

                        builder1 = new AlertDialog.Builder(SetActivity.this);
                        create = builder1.create();
                        create.setTitle("提示");
                        create.setMessage("正在删除缓存...");
                        create.show();
                        handler.sendEmptyMessageDelayed(1, 2000);


                    }
                });

                //显示对话框
                builder.show();
                break;
            case R.id.re_set_textsize:
                AlertDialog.Builder builder2 = new AlertDialog.Builder(SetActivity.this);
                AlertDialog create = builder2.create();
                create.setView(view);
                create.show();
                break;
            case R.id.re_set_liebiao:
                break;
            case R.id.re_set_wifi:
                break;
            case R.id.re_set_tuisong:
                break;
            case R.id.re_set_lixian:
                break;
            case R.id.re_set_check:
                break;
        }
    }
}
